/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1/commercial
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may use this file in compliance with the License.
 * Alternatively, if you can't copy with the License, namely if you do not
 * want to provide source code of your modifications to this file, you may
 * negotiate a commercial licence with the initial developer.
 * You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is COID.
 *
 * The Initial Developer of the Original Code is
 * PosAm.
 * Portions created by the Initial Developer are Copyright (C) 2003
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 * Brano Kemen
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#ifndef __COID_COIDSVC_INSTANCE__HEADER_FILE__
#define __COID_COIDSVC_INSTANCE__HEADER_FILE__

#include "coid/comm/version.h"
#include "coid/comm/retcodes.h"
#include "coid/comm/hptimer.h"
#include "coid/comm/str.h"
#include "coid/comm/local.h"
#include "coid/comm/sync/mutex_reg.h"

#include "cmdin.h"
#include "coid/coid.h"
#include "coid/svc/interfnc.h"

namespace coid {

////////////////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#define COID_GET_FN     coid_get_sdir3d
#define COID_GET_FN2    coid_get_sdir3
#else
#define COID_GET_FN     coid_get_sdir3
#define COID_GET_FN2    coid_get_sdir3d
#endif

#define ___STR(x) #x
#define ___XSTR(x) ___STR(x)
#define COID_GET_FN_NAME ___XSTR(COID_GET_FN)
#define COID_GET_FN_NAME2 ___XSTR(COID_GET_FN2)

/// This method returns ptr to module global service register
#ifdef SYSTYPE_WIN
extern "C" inline __declspec(dllexport) const void* COID_GET_FN()
{
    return &SINGLETON(ClassRegister<ServiceDescriptor>);
}
#else
extern "C" inline __attribute__ ((visibility("default"))) const void* COID_GET_FN()
{
    return &SINGLETON(ClassRegister<ServiceDescriptor>);
}
#endif

////////////////////////////////////////////////////////////////////////////////
/// Instance runtime data for service's dispatch method
/// mirrored for client in coidclient.h
struct InstanceData
{
    cmd_interface*  _cmdin;         ///< command interface to server
    //const HPTIMER*  _hptimer;       ///< high performance timer for sampling

    /// flags for the dispatcher
    uint            _flags;         ///< method flags, see the method flags in ServiceDescriptor

    void*           _object;        ///< ptr to the object

    InstanceData()
    {
        //_hptimer = 0;
        _flags = 0;
    }

    ///Get InstanceData* from cmd_interface
    static InstanceData* cast_ ( cmd_interface* cmdin )
    {
        return (InstanceData*)cmdin;
    }
};

////////////////////////////////////////////////////////////////////////////////
struct CreateInterfaceInfo
{
    version     _clientver;
    uint        _nmethods;
    uint*       _methflags;
    void*       _ifacethis;
    comm_mutex_reg::refmutex* _mutex;

    typedef     opcd (CreateInterfaceInfo::*t_fnc)();
    t_fnc       _disconnect_interface;
};


////////////////////////////////////////////////////////////////////////////////
/// Struct used in dispatch.cpp
struct METHOD_TABLE
{
		const char * name;
		uint id;
//		const char * inpstrn;
//		const char * outpstrn;
};



} // namespace coid

#endif //__COID_COIDSVC_INSTANCE__HEADER_FILE__
